<template>
  <div class="login-container">
    <div class="login-bg">
      <div class="bg-overlay"></div>
    </div>
    
    <div class="login-box">
      <div class="login-header">
        <img src="/logo.svg" alt="logo" class="logo" />
        <h1>家教平台管理系统</h1>
        <p>Education Platform Management System</p>
      </div>
      
      <a-card class="login-card" :bordered="false">
        <a-tabs v-model:activeKey="loginType" centered>
          <a-tab-pane key="account" tab="账号登录">
            <a-form
              :model="formState"
              @finish="handleLogin"
              layout="vertical"
            >
              <a-form-item
                name="mobile"
                :rules="[{ required: true, message: '请输入手机号' }]"
              >
                <a-input
                  v-model:value="formState.mobile"
                  size="large"
                  placeholder="请输入手机号"
                >
                  <template #prefix>
                    <user-outlined class="input-icon" />
                  </template>
                </a-input>
              </a-form-item>
              
              <a-form-item
                name="password"
                :rules="[{ required: true, message: '请输入密码' }]"
              >
                <a-input-password
                  v-model:value="formState.password"
                  size="large"
                  placeholder="请输入密码"
                >
                  <template #prefix>
                    <lock-outlined class="input-icon" />
                  </template>
                </a-input-password>
              </a-form-item>
              
              <a-form-item>
                <div class="login-options">
                  <a-checkbox v-model:checked="formState.remember">
                    记住密码
                  </a-checkbox>
                  <a href="#">忘记密码</a>
                </div>
              </a-form-item>
              
              <a-form-item>
                <a-button
                  type="primary"
                  html-type="submit"
                  size="large"
                  :loading="loading"
                  block
                >
                  登录
                </a-button>
              </a-form-item>
            </a-form>
          </a-tab-pane>
        </a-tabs>
      </a-card>
      
      <div class="login-footer">
        <p>© 2025 家教平台管理系统. All Rights Reserved.</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { message } from 'ant-design-vue'
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'

const router = useRouter()
const userStore = useUserStore()

const loginType = ref('account')
const loading = ref(false)

const formState = reactive({
  mobile: '',
  password: '',
  remember: true
})

const handleLogin = async () => {
  loading.value = true
  
  try {
    await userStore.login({
      mobile: formState.mobile,
      password: formState.password
    })
    
    message.success('登录成功')
    router.push('/')
  } catch (error) {
    message.error(error.message || '登录失败')
  } finally {
    loading.value = false
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  position: relative;
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  
  .bg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="%23ffffff" fill-opacity="0.1" d="M0,96L48,112C96,128,192,160,288,160C384,160,480,128,576,122.7C672,117,768,139,864,128C960,117,1056,75,1152,58.7C1248,43,1344,53,1392,58.7L1440,64L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>') no-repeat bottom;
    background-size: cover;
  }
}

.login-box {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 450px;
  padding: 0 20px;
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
  
  .logo {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
  }
  
  h1 {
    color: #fff;
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 8px;
  }
  
  p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
  }
}

.login-card {
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
  
  :deep(.ant-card-body) {
    padding: 32px;
  }
}

.input-icon {
  color: rgba(0, 0, 0, 0.25);
}

.login-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  
  a {
    color: var(--primary-color);
    
    &:hover {
      color: #40a9ff;
    }
  }
}

.login-footer {
  text-align: center;
  margin-top: 24px;
  
  p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
  }
}
</style>

